<?php



namespace app\common\service\code\driver;

use app\common\service\code\Driver;
use think\Log;

/**
 * Class Qsms
 *
 *
 *
 */
class MxtSms extends Driver
{
    protected $options = [
    ];

    /**
     * 构造函数
     * Qsms constructor.
     *
     * @param array $options
     */
    public function __construct($options = [])
    {
        if (!empty($options)) {
            $this->options = array_merge($this->options, $options);
        }

        $this->handler = null;
    }

    /**
     * 发送短信
     *
     *
     * @param string $whom 手机号
     * @param array $data 附加数据
     * @return bool|string
     */
    public function send($whom, $data = [])
    {
        $result = false;
        try{
            $code = self::buildCache($whom);

            $post_data = array();
            $post_data['account'] = 'MXT800589';
            $post_data['pswd'] = 'Mxt589sms';
            $post_data['mobile'] = $whom;
            $post_data['msg'] = '【聚友支付】代付验证码是: '.$code;
            $post_data['needstatus'] = 'true';
            $url = 'http://www.weiwebs.cn/msg/HttpSendSM';
            $o = '';
            foreach ($post_data as $k => $v) {
                $o .= "$k=".urlencode($v).'&';
            }
            $post_data = substr($o, 0, -1);
    
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
            $result = curl_exec($ch);

        }catch (\Exception $e){
            Log::error("MxtSms Send Fail:" . $e->getMessage());
        }

        return $result;
    }

    /**
     * 验证码检测
     *
     *
     * @param string $whom 手机号
     * @param bool $value 验证码值
     * @return bool|mixed
     */
    public function valid($whom, $value = false)
    {
        return self::checkCache($whom,$value);
    }
}
